# lc1
lc1_lab <- iv_robust(lc1 ~ absenteeism + as.factor(block_id) | Z_absenteeism + as.factor(block_id), data = lab,diagnostics = T)

lc1_lab_pvals <- getParametricPValue(model = lc1_lab,
																		 hypothesis = "upr")

#pta
pta_lab <- iv_robust(pta ~ absenteeism + as.factor(block_id) | Z_absenteeism + as.factor(block_id), data = lab)
pta_lab_pvals <- getParametricPValue(model = pta_lab,
																		 hypothesis = "upr")

# bring_up
bring_up_lab <- iv_robust(bring_up ~ absenteeism + as.factor(block_id) | Z_absenteeism + as.factor(block_id), data = lab)
bring_up_lab_pvals <- getParametricPValue(model = bring_up_lab,
																		 hypothesis = "upr")

#assemble
assemble_lab <- iv_robust(assemble ~ absenteeism + as.factor(block_id) | Z_absenteeism + as.factor(block_id), data = lab)
assemble_lab_pvals <- getParametricPValue(model = assemble_lab,
																					hypothesis = "upr")

# absenteeism_action
absenteeism_action_lab <- iv_robust(absenteeism_action ~ absenteeism + as.factor(block_id) | Z_absenteeism + as.factor(block_id), data = lab)
absenteeism_action_lab_pvals <- getParametricPValue(model = absenteeism_action_lab,
																					hypothesis = "upr")

#setup
control_means <- with(
	lab, 
	c(
		round(mean(lc1[Z_absenteeism == 0],na.rm = TRUE), 2),
		round(mean(bring_up[Z_absenteeism == 0],na.rm = TRUE), 2),
		round(mean(pta[Z_absenteeism == 0],na.rm = TRUE), 2),
		round(mean(assemble[Z_absenteeism == 0],na.rm = TRUE), 2),
		round(mean(absenteeism_action[Z_absenteeism == 0],na.rm = TRUE), 2)
	)
)
control_means <- as.character(control_means)

pval_lines <- c(
	round(lc1_lab_pvals["absenteeism"],3),
	round(bring_up_lab_pvals["absenteeism"],3),
	round(pta_lab_pvals["absenteeism"],3),
	round(assemble_lab_pvals["absenteeism"],3),
	round(absenteeism_action_lab_pvals["absenteeism"],3)
)

hypothesis_lines <- c(
	"upr",
	"upr",
	"upr",
	"upr",
	"upr"
)

sink("03_tables/ABS_attitudes_lab_Z_iv_fe.tex")
print(texreg(l = list(lc1_lab,
								bring_up_lab,
								pta_lab,
								assemble_lab,
								absenteeism_action_lab),
			 omit.coef = "Intercept|block", include.rsquared = F,include.rmse = F,
			 table = F, use.packages = F, custom.gof.names = c("Adjusted R^2", "Observations"),
			 digits = 3, include.ci = FALSE,
			 override.pvalues = list(lc1_lab_pvals,
			 												bring_up_lab_pvals,
			 												pta_lab_pvals, 
			 												assemble_lab_pvals,
			 												absenteeism_action_lab_pvals),
			 stars = c(0.01, 0.05, 0.1),
			 custom.header = list("Involve LC1 Chair" = 1, 
			 										 "Tell village" = 2,
			 										 "Use PTA" = 3,
			 										 "Assemble group" = 4,
			 										 "Index" = 5),
			 custom.model.names =  c("(1)",
			 												"(2)",
			 												"(3)",
			 												"(4)",
			 												"(5)"),
			 custom.gof.rows = list(
			 	"Control Mean" = control_means,
			 	"$p$-values" = pval_lines,
			 	"Hypothesis" = hypothesis_lines,
			 	"Block FE" = c("Yes","Yes","Yes","Yes",
			 		"Yes")),
			 reorder.gof = c(1,2,3,4,6,5)))
sink()


